package gui;

import java.io.Serializable;

import org.primefaces.context.RequestContext;
import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.ChartSeries;

/**
 * Bean for displaying a chart
 * 
 * @author Aleksander Zotov
 * 
 */
public class ChartBean implements Serializable {

	private static final long serialVersionUID = 1L;

	private CartesianChartModel categoryModel;

	public ChartBean() {
		createCategoryModel();
	}

	public CartesianChartModel getCategoryModel() {
		return categoryModel;
	}

	/**
	 * Creates a new chartmodel
	 */
	private void createCategoryModel() {

		categoryModel = new CartesianChartModel();

		ChartSeries refObjects = new ChartSeries();
		refObjects.setLabel("Referenzobjekte");

		if (ListModel.getSelectedSimForPDF() != null) {
			refObjects.set("", ListModel.getSelectedSimForPDF().getRefCount());
		} else {
			refObjects.set("", 0);
		}

		ChartSeries collisions = new ChartSeries();
		collisions.setLabel("Kollisionen");

		if (ListModel.getSelectedSimForPDF() != null) {
			collisions.set("", ListModel.getSelectedSimForPDF()
					.getCollisionCount());
		} else {
			collisions.set("", 0);
		}

		categoryModel.addSeries(refObjects);
		categoryModel.addSeries(collisions);
	}

	/**
	 * Shows dialog with simulation details
	 */
	public void showSimDialog() {
		createCategoryModel();
		RequestContext context = RequestContext.getCurrentInstance();
		context.execute("simDialog.show()");
	}
}